const router = require('koa-router')()
const { User } = require('../models/index')
router.prefix('/users')



//添加用户
router.post('/register', async (ctx, next) => {

    let { name, id, tel, adress, role, IDCard, realName, pwd } = ctx.request.body

    await User.create({ name, id, tel, adress, role, IDCard, realName, pwd }).then(res => {
        //res 此时为一个对象
        if (JSON.stringify(res) != '{}') { //如果返回不为空=>查找成功  反之为查找失败
            ctx.body = {
                code: 200,
                msg: '添加成功',
                data: res
            }
        } else {
            ctx.body = {
                code: 300,
                msg: '添加失败',
            }
        }

    }).catch(err => {
        ctx.body = {
            code: 400,
            msg: '添加时出现异常'
        }
    })
})

module.exports = router
